enum OsnMediaType:Int {
    case general = 0
    case image = 1
    case voice = 2
    case video = 3
    case file = 4
    case portrait = 5
    case favorite = 6
    case sticker = 7
    case moments = 8
    case transfer = 9
    
    init(rawValue: Int) {
        switch rawValue{
        case 0: self = .general
        case 1: self = .image
        case 2: self = .voice
        case 3: self = .video
        case 4: self = .file
        case 5: self = .portrait
        case 6: self = .favorite
        case 7: self = .sticker
        case 8: self = .moments
        case 9: self = .transfer
        default: self = .general
        }
    }
}

class OsnMediaMessageContext: OsnMessageContent {
    var localPath = ""
    var remoteUrl = ""
    var fileSize = 0
    var decKey = ""
    var name = ""
    
    override func toJson() ->[String:Any] {
        var json = super.toJson()
        if !localPath.isEmpty { json["localPath"] = localPath}
        if !remoteUrl.isEmpty { json["remoteUrl"] = remoteUrl}
        if fileSize != 0 { json["fileSize"] = fileSize}
        if !decKey.isEmpty { json["decKey"] = decKey}
        if !name.isEmpty { json["name"] = name}
        return json
    }
    static func fromJson(_ c:OsnMediaMessageContext, _ data:[String:Any]){
        super.fromJson(c, data)
        c.localPath = data["localPath"] as? String ?? ""
        c.remoteUrl = data["remoteUrl"] as? String ?? data["url"] as? String ?? ""
        c.fileSize = data["fileSize"] as? Int ?? 0
        c.decKey = data["decKey"] as? String ?? ""
        c.name = data["name"] as? String ?? ""
    }

}
